<?php
session_start();
$iid = filter_input(INPUT_GET,'iid');
$name = filter_input(INPUT_GET,'name');
$nick = filter_input(INPUT_GET,'nick');
$act = filter_input(INPUT_GET,'act');
if ($act =='add')
{
	$isHave = false;
	$maxOver = false;
	$maxCount = 4;
	if(isset($_SESSION['comItems']))
	{
		if(count($_SESSION['comItems'])>=$maxCount)
		{
			$maxOver=true;
		}else
		{
			foreach($_SESSION['comItems'] as $item)
			{
				if($item[0]==$iid)
				{
					$isHave = true;
					break;
				}
			}
		}
		if (!$maxOver && !$isHave)
		{
			array_push($_SESSION['comItems'],array($iid,$name,$nick));
		}
	}else
	{
		$_SESSION['comItems'][0]=array($iid,$name,$nick);
	}
}elseif($act == 'del')
{
	if (isset($_SESSION['comItems']))
	{
		foreach ($_SESSION['comItems'] as $item)
		{
			if ($item[0] != $iid)
			{
				$temp[]=$item;
			}
		}
		//print_r($temp);
		$_SESSION['comItems']=$temp;
	}
}
if(count($_SESSION['comItems'])>0)
{
	echo json_encode($_SESSION['comItems']);
}else
{
	echo json_encode(array());
}
